namespace LanSunERP
{
    using System;
    using System.ServiceModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;

    public class ForeignKeyList : QueryCommand
    {
        public ForeignKeyList() : base() { }
        public ForeignKeyList(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }
        public SqlCommand BuildCommand()
        {

            switch (RequestJob.Substring(6, 10))
            {
                case "0000000000":
                    /*
                         case "ForeignKeyList":
                            ForeignKeyList m_ForeignKeyList = new ForeignKeyList(cmdSQL, dtRequest, RequestJob);
                            cmdSQL = m_ForeignKeyList.BuildCommand();
                            break;
                    */
                    break;
                case "1000000000":
                    break;
                case "2000000001":
                case "4000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
                case "1000009626":  //DB_ForeignKeyList_DELETE_BY_InstanceID
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
                case "1000009624":  //DB_ForeignKeyList_INSERT
                    break;
                case "1000009628":  //DB_ForeignKeyList_SELECT_ALL
                    break;
                case "1000009630":  //DB_ForeignKeyList_SELECT_BY_InstanceID
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
                case "1000009625":  //DB_ForeignKeyList_SELECT_LIKE
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    break;
                case "1000009627":  //DB_ForeignKeyList_STRUCTURE
                    break;
                case "1000009629":  //DB_ForeignKeyList_UPDATE
                    break;
                case "1000007438":  //IX_ForeignKeyList
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ForeignKey", dwRequest["ForeignKey"].ToString()));
                    break;
                case "1000007440":  //IX_ForeignKeyList_Key
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ForeignKey", dwRequest["ForeignKey"].ToString()));
                    break;
                case "1000007444":  //IX_ForeignKeyList_LikeAny
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    break;
                case "1000007445":  //IX_ForeignKeyList_SysID
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    break;
                case "1000000527":  //IX_ForeignKeyList_TableName
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Type", dwRequest["Type"].ToString()));
                    break;
                case "1000007448":  //PK_ForeignKeyList
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ForeignKey", dwRequest["ForeignKey"].ToString()));
                    break;
                case "1000007447":  //TX_ForeignKeyList
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ForeignKey", dwRequest["ForeignKey"].ToString()));
                    break;
                case "2000000000":
                case "3000000001":
                case "3000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ID", dwRequest["ID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Type", dwRequest["Type"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@BUnique", dwRequest["BUnique"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ForeignKey", dwRequest["ForeignKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TargetTable", dwRequest["TargetTable"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@CheckingType", dwRequest["CheckingType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@UpdateType", dwRequest["UpdateType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@YInstanceTable", dwRequest["YInstanceTable"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key0", dwRequest["Key0"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key1", dwRequest["Key1"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key2", dwRequest["Key2"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key3", dwRequest["Key3"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key4", dwRequest["Key4"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key5", dwRequest["Key5"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key6", dwRequest["Key6"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key7", dwRequest["Key7"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key8", dwRequest["Key8"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key9", dwRequest["Key9"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TForeignKey", dwRequest["TForeignKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey0", dwRequest["TKey0"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey1", dwRequest["TKey1"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey2", dwRequest["TKey2"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey3", dwRequest["TKey3"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey4", dwRequest["TKey4"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey5", dwRequest["TKey5"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey6", dwRequest["TKey6"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey7", dwRequest["TKey7"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey8", dwRequest["TKey8"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey9", dwRequest["TKey9"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    break;
            }
            return cmdSQL;

        }
        public override SqlCommand BuildInstanceKey(SqlCommand cmdSQL, DataRow dwTemp)
        {
            string InstanceKey = dwTemp["InstanceKey"].ToString().Trim();
            string SysID = dwTemp["SysID"].ToString().Trim();
            string ForeignKey = dwTemp["ForeignKey"].ToString().Trim();

            {
                if (SysID != "" && ForeignKey != "")
                {
                    InstanceKey = SysID + "." + ForeignKey;
                    dwTemp["InstanceKey"] = InstanceKey;
                    dwTemp.AcceptChanges();
                }
            }
            cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
            return base.BuildInstanceKey(cmdSQL, dwTemp);
        }
    }
    public class ForeignKeyListQueryCond : QueryCommand
    {
        public ForeignKeyListQueryCond() : base() { }
        public ForeignKeyListQueryCond(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }

        public SqlCommand BuildCommand()
        {
            switch (RequestJob.Substring(6, 10))
            {
                case "0000000000": break;
                case "1000000000": break;
                case "1000000001": break;
                case "1000000002": break;
                case "2000000000":
                case "3000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ID", dwRequest["ID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Type", dwRequest["Type"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@BUnique", dwRequest["BUnique"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ForeignKey", dwRequest["ForeignKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TargetTable", dwRequest["TargetTable"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@CheckingType", dwRequest["CheckingType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@UpdateType", dwRequest["UpdateType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@YInstanceTable", dwRequest["YInstanceTable"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key0", dwRequest["Key0"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key1", dwRequest["Key1"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key2", dwRequest["Key2"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key3", dwRequest["Key3"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key4", dwRequest["Key4"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key5", dwRequest["Key5"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key6", dwRequest["Key6"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key7", dwRequest["Key7"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key8", dwRequest["Key8"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Key9", dwRequest["Key9"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TForeignKey", dwRequest["TForeignKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey0", dwRequest["TKey0"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey1", dwRequest["TKey1"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey2", dwRequest["TKey2"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey3", dwRequest["TKey3"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey4", dwRequest["TKey4"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey5", dwRequest["TKey5"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey6", dwRequest["TKey6"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey7", dwRequest["TKey7"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey8", dwRequest["TKey8"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TKey9", dwRequest["TKey9"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LongDes", dwRequest["LongDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortDes", dwRequest["ShortDes"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@FrstUser", dwRequest["FrstUser"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@FrstDate", dwRequest["FrstDate"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastUser", dwRequest["LastUser"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastDate", dwRequest["LastDate"].ToString()));

                    break;
                case "4000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
            }
            return cmdSQL;

        }

    }
}

